package com.filetransfer.view.Components.render;
import javax.swing.*;
import javax.swing.table.TableCellEditor;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MessageEditor extends AbstractCellEditor implements TableCellEditor {
    private MessageRenderer render = new MessageRenderer();
    private String value;
    public MessageEditor() {
        super();
        render.getViewButton().addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (value != null && !value.trim().isEmpty()) {
                    JOptionPane.showMessageDialog(null, value, "查看消息", JOptionPane.INFORMATION_MESSAGE);
                }
            }
        });
    }
    @Override
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
        this.value = value != null ? value.toString() : null;
        return render.getTableCellRendererComponent(table, value, isSelected, true, row, column);
    }
    @Override
    public Object getCellEditorValue() {
        return value;
    }
}
